package com.sinsoft.monitorDemo.dao;

import java.util.List;

import redis.clients.jedis.Jedis;

import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.sinsoft.monitorDemo.entity.OsOtherInfo;
import com.sinsoft.monitorDemo.util.JsonUtil;
import com.sinsoft.monitorDemo.util.RedisUtil;

public class OsOtherInfoDao {
	
	
	/**
	 * 得到最新的系统资源其他信息运行信息
	 * @param ip
	 * @return
	 */
	public OsOtherInfo getNewCpuInfo(String ip){
		Jedis jedis = RedisUtil.getJedis();
		OsOtherInfo osOtherInfo;
		try {
			List<String> jsonList = jedis.lrange("StatusData_" + ip + "_OSOTHER_latest", -1, -1);
				JsonArray jsonArray = JsonUtil.JsonParse(jsonList.get(0));
				JsonObject jsonObject = jsonArray.get(0).getAsJsonObject();
				osOtherInfo = new OsOtherInfo(jsonObject.get("os_userlogins").getAsInt(), jsonObject.get("os_openfiles").getAsInt(), 
						jsonObject.get("os_uptime").getAsDouble());
		} catch (Exception e) {
			return new OsOtherInfo(null, null, null);
		}
			jedis.close();
		return osOtherInfo;		
	}

}
